package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CDevicesKind;
import com.isunland.managesystem.entity.CDevicesKindOriginalList;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.utils.ParamsNotEmpty;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 选择新建的考勤申请表类型
 *
 * @author wangyanan
 */
//public class RequisitionChooseDialogFragment extends DialogFragment {
//	protected static final int REQUEST_ADD = 100;
//	protected static final String EXTRA_TYPE = "com.isunland.managesystem.ui.RequisitionChooseDialogFragment";
//	private int[] choiceIds = new int[] { R.string.requisitionover,
//			R.string.requisitionunpunch, R.string.requisitionholy,
//			R.string.requisitiontrip, R.string.requisitionout,R.string.requisitionOff };
//	private String[] choiceStrings = new String[choiceIds.length];
//
//	@Override
//	public Dialog onCreateDialog(Bundle savedInstanceState) {
//		return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(
//				getChoiceName(), 0, new OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//
//						String type;
//						switch (which) {
//						case 0:
//
//							type = CheckDetailFragment.VALUE_OVER;
//							break;
//						case 1:
//							type = CheckDetailFragment.VALUE_UNPUNCH;
//							break;
//						case 2:
//							type = CheckDetailFragment.VALUE_HOLY;
//							break;
//						case 3:
//							type = CheckDetailFragment.VALUE_TRIP;
//							break;
//						case 4:
//							type = CheckDetailFragment.VALUE_OUT;
//							break;
//						case 5:
//							type = CheckDetailFragment.VALUE_OFF;
//							break;
//
//						default:
//							type = "";
//							break;
//						}
//
//
//						if (getTargetFragment() == null)
//							return;
//						Intent i = new Intent();
//						i.putExtra(EXTRA_TYPE, type);
//						getTargetFragment().onActivityResult(getTargetRequestCode(),
//								Activity.RESULT_OK, i);
//
//
//						dialog.dismiss();
//					}
//				}).create();
//
//	}
//
//	private String[] getChoiceName() {
//		for (int i = 0; i < choiceIds.length; i++) {
//
//			choiceStrings[i] = getResources().getString(choiceIds[i]);
//		}
//
//		return choiceStrings;
//	}
//
//}

public class EquipmentChooseDialogFragment extends BaseNetworkDialogFragment {
  protected static final String EXTRA_MEMBERCODE =
      "com.isunland.managesystem.ui.RequisitionChooseDialogFragment.EXTRA_MEMBERCODE";

  private String memberCode;

  public static EquipmentChooseDialogFragment newInstance(String membeCcode) {

    Bundle args = new Bundle();
    args.putString(EXTRA_MEMBERCODE, membeCcode);
    EquipmentChooseDialogFragment fragment = new EquipmentChooseDialogFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    if (getArguments() != null) {
      memberCode = getArguments().getString(EXTRA_MEMBERCODE);
    }
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<>();
    CDevicesKindOriginalList original = new Gson().fromJson(arg0, CDevicesKindOriginalList.class);
    ArrayList<CDevicesKind> listDeviceType = original.getRows();

    for (CDevicesKind cDevicesKind : listDeviceType) {
      CustomerDialog dialog =
          new CustomerDialog(cDevicesKind.getDeviceKindName(), cDevicesKind.getDeviceKindCode());
      list.add(dialog);
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.URL_EQUIPMENT_LIST;
  }

  @Override public HashMap<String, String> getparameters() {
    ParamsNotEmpty params = new ParamsNotEmpty();

    params.put("memberCode", memberCode);

    return params.getParams();
  }
}

